<template>
  <div>hhahah</div>
</template>

<script>
export default {
  name: 'seckill',
  props: {
    seckilltabList: {
      type: Array,
      default: () => []
    },
    seckillData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      tabList: []
    };
  },
  watch: {
    seckilltabList: {
      // eslint-disable-next-line no-unused-vars
      handler(newVal, oldVal) {
        this.handleTabListData(newVal);
        console.log('watch===seckilltabList', newVal, this.tabList);
      },
      // immediate: true,
      deep: true
    }
  },
  mounted() {
    console.log('mounted=====', this.seckilltabList);
    this.handleTabListData(this.seckilltabList);
    console.log('mounted=====tabList', this.tabList);
  },
  methods: {
    handleTabListData(list) {
      this.tabList = list.map(item => {
        const newItem = { ...item };
        newItem.pageNum =
          item.campaignProductList && item.campaignProductList.length > 0
            ? 1
            : 0;
        if (this.seckillData.type == 2) {
          if (item.startTime.includes(' ')) {
            newItem.startTime = item.startTime.split(' ')[1];
          }
          newItem.title = item.startTime
            .split(':')
            .slice(0, 2)
            .join(':');
          // 0未开始  1进行中  2 已结束
          newItem.status = Number(item.distanceStartTime) > 0 ? 0 : 1;
        } else {
          newItem.title = item.categoryName;
        }
        return newItem;
      });
    },
    ddd() {
      // 只有当数组为基本数据类型时，map方法才不会改变原始数组，数组为引用类型时，还是会改变原数组的
      // 如何避免： 通过一个新的对象去接收每一个元素，修改后，返回该对象
      this.tabList = this.seckilltabList.map(item => {
        item.pageNum =
          item.campaignProductList && item.campaignProductList.length > 0
            ? 1
            : 0;
        if (this.seckillData.type == 2) {
          if (item.startTime.includes(' ')) {
            item.startTime = item.startTime.split(' ')[1];
          }
          item.title = item.startTime
            .split(':')
            .slice(0, 2)
            .join(':');
          // 0未开始  1进行中  2 已结束
          item.status = Number(item.distanceStartTime) > 0 ? 0 : 1;
        } else {
          item.title = item.categoryName;
        }
        return item;
      });
    }
  }
};
</script>

<style scoped></style>
